<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Route
 *
 * @author miho
 */
class BluesCoders_Router_Route {
    //put your code here

    const PROPERTY_PREFFIX = ':';

    protected $_pattern;

    protected $_parameters;

    protected $_controllerId;

    public function setControllerId($value) {
        $this->_controllerId = $value;
    }

    public function getControllerId() {
        return $this->_controllerId;
    }


    public function setPattern($value) {
        $this->_pattern = $value;
    }

    public function getParameters() {
        return $this->_parameters;
    }

    public function match($uri) {
        $urlItems   = explode('/', $uri);
        $patterns   = explode('/', $this->_pattern);
        $parameters = array();
        

        /*if(sizeof($urlItems) != sizeof($patterns)){
            return false;
        }*/

        foreach ($patterns as $pos=>$key) {
          //url is longer than route, false
          if(!array_key_exists($pos, $urlItems)){
              echo "uri is longer than pattern<br />\n";
            return false;
          }

          if(substr($key, 0, 1) == ':'){
            $key = substr($key, 1);
            $parameters[$key] = $urlItems[$pos];
          }else{
            if($urlItems[$pos] != $key) return false;
          }
        }

        $this->_parameters = $parameters;
        return true;
    }
 }
?>
